package com.lagou.zookeeper.config;

import java.util.StringJoiner;

public class ConfigKeeper {

    /**
     * netty 端口号
     */
    private int nettyPort;

    /**
     * zk 地址： ip + 端口号
     */
    private String zkAddr;

    /**
     * 主动上报时间 秒
     */
    private int interval;

    /**
     * <pre>
     *     区分客户端和服务端
     *     TRUE：SERVER
     *     FALSE：CLIENT
     * </pre>
     *
     */
    private boolean providerSide;

    private static volatile ConfigKeeper configKeeper;

    private ConfigKeeper(){

    }


    public static ConfigKeeper getInstance() {
        if(null == configKeeper){
            configKeeper = new ConfigKeeper();
        }
        return configKeeper;
    }

    public int getNettyPort() {
        return nettyPort;
    }

    public void setNettyPort(int nettyPort) {
        this.nettyPort = nettyPort;
    }

    public String getZkAddr() {
        return zkAddr;
    }

    public void setZkAddr(String zkAddr) {
        this.zkAddr = zkAddr;
    }

    public int getInterval() {
        return interval;
    }

    public void setInterval(int interval) {
        this.interval = interval;
    }

    public boolean isProviderSide() {
        return providerSide;
    }

    public void setProviderSide(boolean providerSide) {
        this.providerSide = providerSide;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", ConfigKeeper.class.getSimpleName() + "[", "]")
                .add("nettyPort=" + nettyPort)
                .add("zkAddr='" + zkAddr + "'")
                .add("interval=" + interval)
                .add("providerSide=" + providerSide)
                .toString();
    }
}
